﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using NUnit.Framework;
using NMock2;

namespace Obra.Test
{
    /// <summary>
    /// Base class to assist with mock testing.
    /// </summary>
    public abstract class NMockTester
    {
        private Mockery mockery;

        public Mockery Mockery
        {
            get { return mockery; }
        }

        [SetUp]
        public virtual void SetUp()
        {
            this.mockery = new Mockery();
        }

        [TearDown]
        public virtual void TearDown()
        {
            this.Mockery.VerifyAllExpectationsHaveBeenMet();
        }

        protected void ExpectOnce(
            Object obj,
            string methodName,
            params IAction [] actions)
        {
            Expect.Once.On(obj)
                .Method(methodName)
                .Will(actions);
        }

        protected void ExpectOnceGetProperty(
            Object obj,
            string methodName,
            IAction action)
        {
            this.ExpectGetProperty(
                obj,
                1,
                methodName,
                action);
        }

        protected void ExpectGetProperty(
            Object obj,
            int count,
            string methodName,
            IAction action)
        {
            Expect.Exactly(count).On(obj)
                .GetProperty(methodName)
                .Will(action);
        }
    }
}
